package com.xianbeiying.app.ckgl.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xianbeiying.app.ckgl.R;
import com.xianbeiying.app.ckgl.bean.SysConfigBean;

import java.util.List;

/**
 * 系统配置数据适配
 */
public class SystemConfigAdapter extends BaseAdapter{
    private Context context;
    private List<SysConfigBean> systemConfigBeanArrayList;
    public SystemConfigAdapter(Context context,List<SysConfigBean> systemConfigBeanArrayList) {
        this.context = context;
        this.systemConfigBeanArrayList=systemConfigBeanArrayList;
    }
    @Override
    public int getCount() {
        return systemConfigBeanArrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_system_config, parent, false);
            holder = new ViewHolder();
            holder.sc_last_line=(View) convertView.findViewById(R.id.sc_last_line);
            holder.iv_sc_img=(ImageView) convertView.findViewById(R.id.iv_sc_img);
            holder.tv_cname=(TextView) convertView.findViewById(R.id.tv_cname);
            holder.tv_sc_type=(TextView) convertView.findViewById(R.id.tv_sc_type);
            holder.tv_sc_time=(TextView) convertView.findViewById(R.id.tv_sc_time);
            holder.tv_grow_content=(TextView) convertView.findViewById(R.id.tv_grow_content);
            holder.tv_zdate_content=(TextView) convertView.findViewById(R.id.tv_zdate_content);
            holder.tv_cdate_content=(TextView) convertView.findViewById(R.id.tv_cdate_content);
            holder.tv_line=(TextView) convertView.findViewById(R.id.tv_line);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.sc_last_line.setVisibility(View.VISIBLE);
        if((position+1)==systemConfigBeanArrayList.size()){
        holder.sc_last_line.setVisibility(View.VISIBLE);
        }
        holder.tv_cname.setText(systemConfigBeanArrayList.get(position).getConfigBean().get(0).getPlantName());
        holder.tv_sc_type.setText(systemConfigBeanArrayList.get(position).getConfigBean().get(0).getPlantType()==0?"育苗":"种植");
        holder.tv_grow_content.setText(systemConfigBeanArrayList.get(position).getConfigBean().get(0).getStepName());
//        holder.tv_sc_time.setText("");
//        holder.tv_grow_content.setText("");
//        holder.tv_cdate_content.setText("");
        holder.tv_cdate_content.setText(systemConfigBeanArrayList.get(position).getNumber()+"");

        return convertView;
    }
    private class ViewHolder{
        ImageView iv_sc_img;
        TextView tv_cname;
        TextView tv_sc_type;
        TextView tv_sc_time;
        TextView tv_grow_content;
        TextView tv_zdate_content;
        TextView tv_cdate_content;
        View sc_last_line;
        TextView tv_line;
    }
}
